﻿using Shop.Model.DB;
using Shop.Model.FrontCategory;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.IdGenerator;
using WeDonekRpc.SqlSugar;

namespace Shop.Repository.lmpl
{
    internal class FrontCategoryBindRepository : ShopBaseRepository<DBFrontCategoryBind, long>, IFrontCategoryBindRepository
    {
        public FrontCategoryBindRepository (ISqlClientFactory factory) : base(factory)
        {
        }
        public void Add (FrontBindAdd add)
        {
            base.Insert(add.CategoryId.ConvertAll(a => new DBFrontCategoryBind
            {
                CategoryId = a,
                Lvl = add.Lvl,
                FrontCategoryId = add.FrontId,
                Id = IdentityHelper.CreateId()
            }));
        }
        public void Set (FrontBindAdd add, long[] dropId)
        {
            ISqlQueue<DBFrontCategoryBind> queue = base.BeginQueue();
            queue.Delete(a => dropId.Contains(a.Id));
            queue.Insert(add.CategoryId.ConvertAll(a => new DBFrontCategoryBind
            {
                CategoryId = a,
                Lvl = add.Lvl,
                FrontCategoryId = add.FrontId,
                Id = IdentityHelper.CreateId()
            }));
            _ = queue.Submit();
        }
    }
}
